package com.ddm.service.impl.webImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ddm.dto.webDTO.StandardDTO;
import com.ddm.mapper.StandardFileMapper;
import com.ddm.service.webService.StandardFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class StandardFileServiceImpl implements StandardFileService {

    @Autowired
    private StandardFileMapper standardFileMapper;

    @Override
    public StandardDTO getStandardFileById(Integer id) {
        if (id == null) {
            return null;
        }
        return standardFileMapper.selectStandardFileById(id);
    }

    @Override
    public IPage<StandardDTO> selectStandardByPage(Page<StandardDTO> page, String level, String key) {
        // 确保 Mapper 方法参数类型匹配
        if (key == null) {
            key = "";
        }
        if (level == null) {
            level = "";
        }
        return standardFileMapper.selectStandardByPage(page, level, key);
    }


    @Override
    public IPage<StandardDTO> getCollectedStandardFileByUserId(Page<StandardDTO> page, Integer userId, String key) {
        log.info("开始查询用户收藏标准文件 | userId: {}, 页码: {}, 每页条数: {}, 关键词: {}",
                userId, page.getCurrent(), page.getSize(), key);

        // 直接调用Mapper的新方法，返回IPage<StandardDTO>
        IPage<StandardDTO> resultPage = standardFileMapper.selectCollectedStandardByUserId(page, userId, key);

        log.info("查询结果: 总记录数: {}, 当前页记录数: {}",
                resultPage.getTotal(), resultPage.getRecords().size());

        return resultPage;
    }
}
